package com.tinem.platform.module.starter.web.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author fengzhihao
 * @version v1
 * @program: platform
 * @className IpConfig
 * @description TODO
 * @site
 * @company
 * @create 2020-07-13 19:11
 */
@Configuration
@EnableSwagger2
public class SwaggerConfiguration {

    @Value("${info.groupId}")
    String groupId;
    @Value("${info.artifactId}")
    String artifactId;
    @Value("${info.version}")
    String version;
    @Value("${swagger.enable}")
    String enable;

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title(artifactId)
                .description(groupId+"."+artifactId)
                .version(version)
                .contact(new Contact("fzh","http://www.fengzhihao.xyz","1209103220@qq.com"))
                .build();
    }
    @Bean
    public Docket newsApi() {
        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        docket.enable(true);

        docket.apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any()).build();;
        return docket;
    }

}
